/*
 * This file is part of animus, a GUI for the command line app "GHost++"
 *
 * http://code.google.com/p/animus/
 *
 * Copyright (C) 2008-2009 Lucas Romero
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */


using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.ComponentModel;

namespace animus
{
    public class ConsoleTriggerTrayBalloon : ConsoleTrigger
    {
        public override string GetDescription()
        {
            return "Show a balloon popup in tray";
        }
        public ConsoleTriggerTrayBalloon()
            : base()
        {
            //default constructor
        }
        protected static NotifyIcon m_NotifyIcon = null;
        public static void SetNotifyIcon(NotifyIcon notifyIcon)
        {
            m_NotifyIcon = notifyIcon;
        }
        protected ToolTipIcon m_BalloonIcon = ToolTipIcon.Info;
        [Category("Popup")]
        [Description("The icon type that will be shown in the popup")]
        public ToolTipIcon BalloonIcon
        {
            get { return m_BalloonIcon; }
            set { m_BalloonIcon = value; }
        }
        protected string m_BalloonTitle = "Notice";
        [Category("Popup")]
        [Description("The title shown in the popup (supports regex replacers)")]
        public string BalloonTitle
        {
            get { return m_BalloonTitle; }
            set { m_BalloonTitle = value; }
        }
        protected string m_BalloonText = "You can use normal text or regex replacers like $1 here and in the title.";
        [Category("Popup")]
        [Description("The text shown in the popup (supports regex replacers)")]
        public string BalloonText
        {
            get { return m_BalloonText; }
            set { m_BalloonText = value; }
        }
        protected int m_Timeout = 5;
        [Category("Popup")]
        [Description("The popup will be hidden after this number of seconds")]
        public int Timeout
        {
            get { return m_Timeout; }
            set { m_Timeout = value; }
        }
        protected bool m_DontUseRegexReplace = false;
        [Category("Advanced")]
        [Description("Disable the usage of regex replacers in 'BalloonText' and 'BalloonTitle' properties")]
        public bool DontUseRegexReplace
        {
            get { return m_DontUseRegexReplace; }
            set { m_DontUseRegexReplace = value; }
        }
        public override string GetParameters()
        {
            return "Title: " + m_BalloonTitle + " - Text: " + m_BalloonText;
        }
        protected override void Triggered(string line, Match match)
        {
            string title;
            string text;
            if (!m_DontUseRegexReplace)
            {
                title = match.Result(m_BalloonTitle);
                text = match.Result(m_BalloonText);
            }
            else
            {
                title = m_BalloonTitle;
                text = m_BalloonText;
            }
            
            m_NotifyIcon.ShowBalloonTip(m_Timeout, title, text, m_BalloonIcon);
        }
    }
}
